package com.qinchen;

import com.qinchen.service.IUserService;
import com.qinchen.service.OrderService;
import com.qinchen.spring.AppConfig;
import com.qinchen.spring.ApplicationContext;

/**
 * @author 钦尘
 * @date 2021/9/30 5:54
 * @description 测试手写spring
 */
public class Test {

    public static void main(String[] args) {

        // 扫描bean 创建bean 依赖注入 执行Aware回调 执行Bean后置处理器 放入单例池，核心逻辑都在构造方法中
        ApplicationContext applicationContext = new ApplicationContext(AppConfig.class);

        // 测试单例 或 原型
        IUserService userService1 = (IUserService) applicationContext.getBean("userService");
        IUserService userService2 = (IUserService) applicationContext.getBean("userService");
        System.out.println(userService1);
        System.out.println(userService2);

        OrderService orderService = (OrderService) applicationContext.getBean("orderService");
        System.out.println(orderService);

        // 从单例池获取到bean
        IUserService userService = (IUserService) applicationContext.getBean("userService");

        // 调用bean的方法
        String result = userService.login();

        System.out.println(result);

    }

}
